using System;
using System.Collections.Generic;
using Godot;

public partial class RobotEntity : RobotModel
{
    public int ID;

    public PilotEntity Pilot;
    public List<ItemEntity> EquipmentList = new();
    public List<BuffEntity> BuffList = new();
    public List<WeaponEntity> WeaponList = new();

    public BaseProperty ExtraProperty
    {
        get
        {
            BaseProperty property = new();
            foreach (var buff in BuffList)
            {
                property += buff.Property;
            }
            foreach (var item in EquipmentList)
            {
                property += item.Property;
            }
            return property;
        }
    }
    public int Exp;
    public int MaxExp => 20 + Mathf.CeilToInt(20 * Mathf.Pow(Level, 1.3)) / 10 * 10;
    public int Level;
    public int CurrentHealth;
    public int BaseHealth => Health + ExtraProperty.Health + GameUtil.CalcLevelPlus(HealthPlus, Level) + (Pilot?.Health ?? 0);
    public int CurrentSprite;
    public int BaseSprite => Sprite + ExtraProperty.Sprite + GameUtil.CalcLevelPlus(Pilot?.SpritePlus ?? 5, Level) + (Pilot?.Sprite ?? 0);
    public int BaseAttack => Attack + ExtraProperty.Attack + GameUtil.CalcLevelPlus(AttackPlus, Level) + (Pilot?.Attack ?? 0);
    public int BaseDefense => Defense + ExtraProperty.Defense + GameUtil.CalcLevelPlus(DefensePlus, Level) + (Pilot?.Defense ?? 0);
    public int BaseSpeed => Speed + ExtraProperty.Speed + GameUtil.CalcLevelPlus(SpeedPlus, Level) + (Pilot?.Speed ?? 0);
    public int BaseMovement => Movement + ExtraProperty.Movement + (Pilot?.Movement ?? 0);
    public int BaseHitRate
    {
        get => HitRate;
    }

    public int TotalHealth => Mathf.CeilToInt(BaseHealth * (1 + ExtraProperty.HealthPercent));
    public int TotalSprite => Mathf.CeilToInt(BaseSprite * (1 + ExtraProperty.SpritePercent));
    public int TotalAttack => Mathf.CeilToInt(BaseAttack * (1 + ExtraProperty.AttackPercent));
    public int TotalDefense => Mathf.CeilToInt(BaseDefense * (1 + ExtraProperty.DefensePercent));
    public int TotalSpeed => Mathf.CeilToInt(BaseSpeed * (1 + ExtraProperty.SpeedPercent));
    public int TotalMovement => Mathf.CeilToInt(BaseMovement * (1 + ExtraProperty.MovementPercent));

    public int TotalHitRate => BaseHitRate + ExtraProperty.HitRate;


    public RobotEntity(RobotModel md, int id)
    {
        ID = id;
        GameUtil.FastAssignment(md, this);
    }
    public RobotEntity(RobotModel md, PilotModel pmd, int id, Robot owner)
    {
        ID = id;
        GameUtil.FastAssignment(md, this);
        Pilot = new PilotEntity(pmd, 0);
        foreach (var item in md.Weapons)
        {
            WeaponList.Add(WeaponManager.Create(Global.WeaponModelDic[item], owner));
        }
    }
}